
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../common/style/colors.dart';


class ToolsBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final List<Widget>? actions;
  const ToolsBar({
    Key? key,
    required this.title,
    this.actions
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
    final bool canPop = parentRoute?.canPop ?? false;
    var empty = const SizedBox();
    return PreferredSize(
      preferredSize: const Size(0.0, 100),
      child: SafeArea(
        child: SizedBox(
          width: MediaQuery.of(context).size.width,
          height: 48.h,
          child: ClipRRect(
            child: Stack(
              children: [
                Container(
                    alignment: Alignment.center,
                    child: Text(
                      title,
                      style: TextStyle(color: AppColors.color332B29, fontWeight: FontWeight.w600, fontSize: 16.sp),
                    )),
                Flex(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  direction: Axis.horizontal,
                  children: [
                    Visibility(
                        visible: canPop,
                        child: IconButton(
                            iconSize: 22.r,
                            padding: const EdgeInsets.all(4),
                            onPressed: () {Get.back();},
                            icon: const Icon(
                              Icons.arrow_back_ios,
                            ))),
                    actions == null
                        ? empty
                        : Row(
                            children: actions!,
                          ),
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  Size get preferredSize => Size(ScreenUtil().setWidth(750), ScreenUtil().setHeight(105));
}
